package com.laixu.estore.web.controller;

import com.laixu.estore.service.CollectService;
import com.laixu.estore.web.response.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("collect")
public class CollectController {
    private final CollectService collectService;
    @PostMapping("/{id}")
    public Result addCollect(@PathVariable Integer id, HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        collectService.addCollect(id,userId);
        return Result.success();
    }
    @GetMapping("/")
    public Result list(HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        return Result.success(collectService.list(userId));
    }
    @DeleteMapping("/")
    public Result delete(@RequestBody List<Integer> ids) {
        collectService.delete(ids);
        return Result.success();
    }

}
